<% if !@my_stocks.empty? %>
<h1>Your Current Portfolio</h1>
<table>
  <tr>
    <th>Name</th>
    <th>Quantity</th>
    <th>Bought at</th>
    <th>Market value</th>
    <th>Total value</th>
    <th /><th />
  </tr>
<% total_value = 0 %>
<% for stock in @my_stocks %>
<% name, market_value = Ownership.details(stock.stock_id) %>
<% value = market_value*stock.quantity %>
<% total_value += value %>
  <tr>
    <td><%= link_to name, 	:controller => 'market',
    						:action => 'show',
    						:id		=> stock.stock_id  %></td>
    <td><%=h stock.quantity %></td>
    <td><%=h stock.bought_at %></td>
    <td><%=h number_with_precision(market_value, 2) %></td>
	<td><%=h number_with_precision(value, 2) %></td>
	<td><%= link_to 'Sell', 
			:controller => 'market',
            :action => 'sell_all',
            :id      => stock.stock_id %> | 
    	<%= link_to 'Buy More', 
			:controller => 'market',
            :action => 'buy',
            :id      => stock.stock_id %></td>
  </tr>
<% end %>
</table>
<% else 
	total_value = 0 %>
<h2>You do not own any stocks</h2>
<% end %>
<table>
  <tr>
    <td><h3>Total Stock Value:</h3></td>
    
    <td></td>
    <td></td>
	<td><h3><%=h number_with_precision(total_value, 2) %></h3></td>
  </tr>
    <tr>
    <td><h3>Cash at Hand :</h3></td>
    <td></td>
    <td></td>
	<td><h3><%=h number_with_precision(@my_cash, 2) %></h3></td>
  </tr>
    </tr>
    <tr>
    <td><h3>Net Worth :</h3></td>
    <td></td>
    <td></td>
	<td><h3><%=h number_with_precision(@my_cash+total_value, 2) %></h3></td>
  </tr>
</table>
<p>Visit the <%= link_to 'Market',      :controller => 'market'%> to Buy or Sell Stocks!</p>
